define('ui/page/list/destination', function(require, exports, module){
	var $ = require('lib/jquery'),
		Util = require('module/util'),
		ImgLazyLoad = require('ui/widget/imglazyload'),
		site = require('ui/page/site'),
		undefined;
	var positions = [];
	var Page = module.exports = {};
	Page.init = function(){
		site.init();
		initPage();
		ImgLazyLoad.show();
		initEvent();
	}
	function initPage(){
		var func = window.onload;
		window.onload = function(){
			func && func();
			initPosition();
			var location = Util.getParam('location');
			if (location != '') {
				var top = positions[location];
				$(document).scrollTop(top-(126+24));
			}
			$(window).trigger("scroll");
		}
	}
	function initPosition(){
		$('.destination-li').each(function(index, item){
			var $item = $(item),
				top = $item.offset().top;
			positions.push(top);
		});
	}
	function checkPosition(){
		var scrollHeight = $(document).scrollTop()+$(window).height()/2, curView = 0;
        for (var i = 0; i < positions.length; i++) {
            var curPos = positions[i];
            if (scrollHeight >= curPos) {
                curView = i;
            };
        };
        $('.j_link').removeClass('active');
        $('.j_link').eq(curView).addClass('active');
	}
	function initEvent(){
		$('.j_link').on('click', function(){
			var index = $('.j_link').index(this), top = positions[index];
			if (!top) {
				initPosition();
			};
			top = top - (126+24);
			$('html,body').animate({'scrollTop':top+'px'}, 600);
			$(this).siblings('a').removeClass('active');
			$(this).addClass('active');
		});
		var _timer;
        $(window).bind("scroll",function() {
            clearTimeout(_timer);
            _timer = setTimeout(checkPosition, 200);
        });
	}
});